<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<div id="allmap" style="width:750px;height:500px;margin: auto auto 100px;" ></div>
<div>
    <span>
        
    </span>
</div>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script>
<script type="text/javascript">
    var baiduMap = {};
    baiduMap = function(){
		var ary;
		var map;
		var point;
        return {
            add : function(id,json){
	            ary = new Array();
			    map = new BMap.Map("allmap");
			    map.enableScrollWheelZoom();
			    map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT})); //右上角，仅包含平移和缩放按钮
			    map.addControl(new BMap.MapTypeControl({
				    mapTypes: [BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP, BMAP_HYBRID_MAP],
				    anchor: BMAP_ANCHOR_TOP_LEFT
			    })); //2D图，卫星图
			    var data = eval(json);
				for(var i=0; i<data.length; i++){
					point = new BMap.Point(data[i]['itude'][0], data[i]['itude'][1]);
				    ary.push(new BMap.Point(data[i]['itude'][0], data[i]['itude'][1]));
				    this.addMarker(point, data[i]['logo'], data[i]['price']);
				}
            },
            addMarker: function(point, pic , price){
                var marker = new BMap.Marker(point);
                map.addOverlay(marker);
                var jsondata = map.getViewport(ary);
                map.centerAndZoom(jsondata.center, jsondata.zoom - 1);
                var sContent = "<div><span><img src='"+pic+"'></span><span>"+price+"起</span></div>";
                var infoWindow = new BMap.InfoWindow(sContent); // 创建信息窗口对象
                var label = new BMap.Label(sContent, {
                            offset: new BMap.Size(0, -30)
                        });
                marker.setLabel(label);
                label.setStyle({
                    border: "none",
                    cursor: "pointer"
                });
                infoWindow.addEventListener("open", function(){
                    marker.getLabel().hide();
                });
                infoWindow.addEventListener("close", function(){
                    marker.getLabel().show();
                });
                label.addEventListener("click", function(){
                    window.open('showhotel.php?hotel_id=' + hid + '&cid=2355674321&uid=2355674321');
                });
                // var markerClusterer = new BMapLib.MarkerClusterer(map, {markers:ary});点聚合  有报错
            }
        }
    }();
	
</script>
<script>window.load = baiduMap.add('baidu_map',[{"hotel_id":"58","itude":["115.893528","28.689578"],"price":"450.00","logo":"images\/82_46.jpg"},{"hotel_id":"3564","itude":["116.413002","40.013998"],"price":"898.00","logo":"images\/82_46.jpg"},{"hotel_id":"3580","itude":["23.430467","23.430467"],"price":"918.00","logo":"images\/82_46.jpg"}]);</script>

</body>
</html>